DigWindow = function() {
	this.domain = new Ext.form.TextField({
		fieldLabel: 'Enter <b>domain</b> to dig',
		width: 300,
		validationEvent: false,
		allowBlank: false,
	//	id: 'domain',
		blankText: 'Domain is required.',
		msgTarget: 'under',
		// without these listeners the window will look funny after an error message
		listeners: {
			valid: this.syncShadow,
			invalid: this.syncShadow,
			scope: this
		}
	});
	
	
	var typeData = new Ext.data.SimpleStore({
	fields: ['display', 'value'],
		data: [
			['A', 'A'],
			['AAAA', 'A'], 
			['CNAME', 'CNAME'],
			['MX', 'MX'],
			['NS', 'NS'],
			['SOA', 'SOA'],
			['TXT', 'TXT']
		]
	});
	
	this.type =  new Ext.form.ComboBox({
		store: typeData,
		displayField:'display',
		editable: false,
		forceSelection: true,
		emptyText: "Select Type",
		mode: 'local',
		fieldLabel: "Type",
		triggerAction: 'all',
		selectOnFocus:true,
		resizable:false,
		listWidth: 100,
		width: 100,
		valueField: 'value'
	});
	
	this.result = new Ext.form.TextArea({
		fieldLabel: 'Result',
		width: 400,
		height: 150,
	//	id: 'result',
		// without these listeners the window will look funny after an error message
		listeners: {
			valid: this.syncShadow,
			invalid: this.syncShadow,
			scope: this
		}
	});
	
	this.form = new Ext.FormPanel({
		labelAlign:'top',
		items: [this.domain,  this.type, this.result],
		border: false,
		bodyStyle:'background:transparent;padding:10px;'
	});
	
	DigWindow.superclass.constructor.call(this, {
		title:'Dig',
		iconCls:'commands-icon',
		//id: 'digWindow',
		width:500,
		height: 400,
		//id: 'digWindow',
		resizable:true,
		plain:true,
		modal: false,
		y: 100,
		autoScroll: true,
		closeAction: 'hide',
		buttons:[{
			text: 'Query Domain',
			handler: this.exec,
			scope: this
		},{
			text: 'Cancel',
			handler: this.hide.createDelegate(this, []) // hide
		}],
		
		items: this.form,
		focus: function(){
			this.domain.focus(); // set focus
		}
	});
}

Ext.extend(DigWindow, Ext.Window, {
	show : function(){
		if(this.rendered){
			//this.zone.setValue(''); // reset text field
			//this.zone.clearInvalid(); // clears the default empty warning
			
		}
		DigWindow.superclass.show.apply(this, arguments);
	},
	exec: function() {
		this.el.mask('Processing...', 'x-mask-loading');
		var domain = this.domain.getValue();
		Ext.Ajax.request({
			url: 'xhr/tools/dig.php',
			params: {
				domain: domain,
				type: this.type.getValue()
			},
			success: function(response, options){
				this.domain.clearInvalid(); // clear error messages
				
				var jsonData = new Object;
				try {
					jsonData = Ext.util.JSON.decode(response.responseText);
				}
				catch (err) {
					jsonData.success = false;
					jsonData.msg = "Error decoding JSON response!";
				}
				
				if (jsonData.success) {
					
					console.debug('success');
					//this.addZone(zone);
					this.el.unmask();
					// display html output
					this.result.setValue(jsonData.text);
				} else {
					this.domain.markInvalid(jsonData.msg);
					this.el.unmask();
				}
				Ext.ux.Status.log({
					msg: jsonData.msg,
					success: jsonData.success
				});
			},
			failure: function(response, options){
				this.dmoain.markInvalid('Cannot quere domain. XHR failure!');
				this.el.unmask();
				// log to status panel
				Ext.ux.Status.log({
					msg: "Cannot query domain. XHR failure!",
					type: 'error'
				});
			},
			scope: this
		});
	}
});